/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package failuremodule;

import comunicacao.RmiClientApp;
import entities.Server;
import java.awt.Color;

/**
 *
  * @author Leonardo Lino Nº45340
 * @author Diogo Pires Nº40351
 */
public class ServerPainel extends javax.swing.JPanel {
    
    public static final int ESTADO_ONLINE = 0;
    public static final int ESTADO_OFFLINE = 1;
    private int estado = 0;
    private Server server;

    /**
     * Creates new form ServerPainel
     */
    public ServerPainel() {
        initComponents();
        setBackground(Color.GREEN);
        buttonRestart.setEnabled(false);
    }

    public int getEstado() {
        return estado;
    }

    public void setEstado(int estado) {
        this.estado = estado;
    }

    public Server getServer() {
        return server;
    }

    public void setServer(Server server) {
        this.server = server;
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this
     * method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nodeNameLabel = new javax.swing.JLabel();
        buttonFail = new javax.swing.JButton();
        buttonRestart = new javax.swing.JButton();

        nodeNameLabel.setText("Nome");

        buttonFail.setText("Fail");
        buttonFail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFailActionPerformed(evt);
            }
        });

        buttonRestart.setText("Restart");
        buttonRestart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRestartActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nodeNameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
                        .addComponent(buttonFail))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(buttonRestart)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(buttonFail))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(nodeNameLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonRestart)
                .addContainerGap(18, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void buttonFailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFailActionPerformed
        
        buttonFail.setEnabled(false);
        buttonRestart.setEnabled(true);
        this.setBackground(Color.RED);
        RmiClientApp client = new RmiClientApp();
        client.falha(server);
        
    }//GEN-LAST:event_buttonFailActionPerformed

    private void buttonRestartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRestartActionPerformed
        buttonFail.setEnabled(true);
        buttonRestart.setEnabled(false);
        this.setBackground(Color.GREEN);
        RmiClientApp client = new RmiClientApp();
        client.restart(server);
        
    }//GEN-LAST:event_buttonRestartActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonFail;
    private javax.swing.JButton buttonRestart;
    public javax.swing.JLabel nodeNameLabel;
    // End of variables declaration//GEN-END:variables
}
